package com.jwater.web.ui.tag.components;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.ClosingUIBean;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;

import com.opensymphony.xwork2.util.ValueStack;

@StrutsTag(name = "pager", tldTagClass = "com.jwater.web.ui.tags.PagerTag", description = "pager", allowDynamicAttributes = true)
public class Pager extends ClosingUIBean {

	public static final String TEMPLATE = "pager";
	public static final String TEMPLATE_CLOSE = "pager-close";
	public static final String COMPONENT_NAME = Pager.class.getName();
	
	protected String href;
	protected String displayNum;

	@StrutsTagAttribute(description="href.eg:http://www.domainname.com/user.action?user_id=1&pageIndex=#PAGE_INDEX#", type="String")
	public void setHref(String href) {
		this.href = href;
	}
	
	@StrutsTagAttribute(description="display number number", type="Integer")
	public String getDisplayNum() {
		return displayNum;
	}

	public void setDisplayNum(String displayNum) {
		this.displayNum = displayNum;
	}

	public Pager(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
		super(stack, request, response);
	}

	@Override
	public String getDefaultOpenTemplate() {
		return TEMPLATE;
	}

	@Override
	protected String getDefaultTemplate() {
		return TEMPLATE_CLOSE;
	}

	@Override
	protected void evaluateExtraParams() {
		// TODO Auto-generated method stub
		super.evaluateExtraParams();
		if (href != null)
			addParameter("href", findString(href));
		if(displayNum != null)
			addParameter("displayNum", findValue(displayNum,Integer.class));
	}
	
}
